@file:Suppress("NOTHING_TO_INLINE")

package tech.summerly.weather.util

import android.content.Context
import android.support.annotation.ColorInt
import android.support.annotation.ColorRes
import android.support.annotation.DrawableRes
import android.support.annotation.StringRes
import android.support.v4.content.ContextCompat
import android.widget.Toast
import tech.summerly.weather.AppContext

/**
 * 对获取 Android Resource 的一层简单的封装，方便调用
 */

private val context1 get() = AppContext.instance

fun string(@StringRes stringId: Int) = context1.getString(stringId)!!

fun string(@StringRes stringId: Int, vararg formatArgs: Any) = string(stringId).format(*formatArgs)

fun color(@ColorRes colorId: Int, context: Context = context1) = ContextCompat.getColor(context, colorId)

fun drawable(@DrawableRes id: Int, @ColorInt tint: Int = 0) = context1.getDrawable(id)!!.also {
    if (tint != 0) {
        it.setTint(tint)
    }
}

inline fun Context.toast(message: CharSequence): Toast = Toast
        .makeText(this, message, Toast.LENGTH_SHORT)
        .apply {
            show()
        }